﻿''' <summary>
''' Kiểm kê tài sản
''' </summary>
''' <remarks></remarks>
Public Class InventoryDTO
    Inherits Inventory_X

    Private _id As Integer 'Mã tài sản
    Private _cost As Integer 'Nguyên giá
    Private _costImpoverishment As Integer 'Giá trị hao mòn
    Private _costRemaining As Integer 'Giá trị còn lại
    Private _techCondition As String 'Tình trạng kỹ thuật
    Private _date As Date 'Thời gian
    Private _place As String 'Địa điểm
    Private _councilInventory As Integer 'Hội đồng kiểm kê
    Private _fatype As Integer 'Loại tài sản cố định
    Private _status As Integer 'Trạng thái chứng từ

    Private _behave As Integer



    Public Sub New(ByVal id As Integer, ByVal cost As Integer, ByVal costImpoverishment As Integer, ByVal costRemaining As Integer, ByVal techCondition As String, ByVal date1 As Date, ByVal place As String, ByVal councilInventory As Integer, ByVal fatype As Integer)
        Me._id = id
        Me._cost = cost
        Me._costImpoverishment = costImpoverishment
        Me._costRemaining = costRemaining
        Me._techCondition = techCondition
        Me._date = date1
        Me._place = place
        Me._councilInventory = councilInventory
        Me._fatype = fatype
        Me._status = CONSTANT.STATUS._DRAFTS

        Me._behave = CONSTANT.BEHAVE_TYPE._INSERT

    End Sub


    Public Sub New(ByVal id As Integer)
        MyBase.New()
        Dim mySqlConnect As MySqlConnect
        mySqlConnect = New MySqlConnect

        Dim da As DataTable
        da = New DataTable
        Dim aSql = "SELECT *FROM " & MyBase.TABLE_NAME & ""
        aSql += " WHERE " & MyBase.COLUMN_NAME_id & " = " & id & ""

        da = mySqlConnect.executeQuery(aSql)
        If (da Is Nothing) Then
            Return
        End If

        Me._id = CType(da.Rows(0)(MyBase.COLUMN_NAME_id), Integer)
        Me._cost = CType(da.Rows(0)(MyBase.COLUMN_NAME_cost), Integer)
        Me._costImpoverishment = CType(da.Rows(0)(MyBase.COLUMN_NAME_costImpoverishment), Integer)
        Me._costRemaining = CType(da.Rows(0)(MyBase.COLUMN_NAME_costRemaining), Integer)
        Me._techCondition = CType(da.Rows(0)(MyBase.COLUMN_NAME_techCondition), String)
        Me._date = CType(da.Rows(0)(MyBase.COLUMN_NAME_date), Date)
        Me._place = CType(da.Rows(0)(MyBase.COLUMN_NAME_place), String)
        Me._councilInventory = CType(da.Rows(0)(MyBase.COLUMN_NAME_councilInventory), Integer)
        Me._fatype = CType(da.Rows(0)(MyBase.COLUMN_NAME_fatype), Integer)
        Me._status = CType(da.Rows(0)(MyBase.COLUMN_NAME_status), Integer)



        Me._behave = CONSTANT.BEHAVE_TYPE._UPDATE
    End Sub

    Public Function save() As Boolean
        Dim mySqlConnect As MySqlConnect
        mySqlConnect = New MySqlConnect

        Dim aSql As String
        aSql = ""
        Select Case Me._behave
            Case CONSTANT.BEHAVE_TYPE._UPDATE
                aSql = "UPDATE " & MyBase.TABLE_NAME & ""
                aSql += " SET " & MyBase.COLUMN_NAME_id & " = " & Me._id & ""
                aSql += " ," & MyBase.COLUMN_NAME_cost & " = " & Me._cost & ""
                aSql += " ," & MyBase.COLUMN_NAME_costImpoverishment & " = " & Me._costImpoverishment & ""
                aSql += " ," & MyBase.COLUMN_NAME_costRemaining & " = " & Me._costRemaining & ""
                aSql += " ," & MyBase.COLUMN_NAME_techCondition & " = '" & Me._techCondition & "'"
                aSql += " ," & MyBase.COLUMN_NAME_date & " = " & Me._date & ""
                aSql += " ," & MyBase.COLUMN_NAME_place & " = '" & Me._place & "'"
                aSql += " ," & MyBase.COLUMN_NAME_councilInventory & " = " & Me._councilInventory & ""
                aSql += " ," & MyBase.COLUMN_NAME_fatype & " = " & Me._fatype & ""
                aSql += " ," & MyBase.COLUMN_NAME_status & " = " & Me._status & ""
                aSql += " WHERE " & MyBase.COLUMN_NAME_id & " = " & Me._id & ""
                mySqlConnect.executeUpdate(aSql)

            Case CONSTANT.BEHAVE_TYPE._INSERT
                aSql = "INSERT INTO " & MyBase.TABLE_NAME & ""
                aSql += "( "
                aSql += " " & MyBase.COLUMN_NAME_id & " "
                aSql += " " & MyBase.COLUMN_NAME_cost & " "
                aSql += " " & MyBase.COLUMN_NAME_costImpoverishment & " "
                aSql += " " & MyBase.COLUMN_NAME_costRemaining & " "
                aSql += " " & MyBase.COLUMN_NAME_techCondition & " "
                aSql += " " & MyBase.COLUMN_NAME_date & " "
                aSql += " " & MyBase.COLUMN_NAME_place & " "
                aSql += " " & MyBase.COLUMN_NAME_councilInventory & " "
                aSql += " " & MyBase.COLUMN_NAME_fatype & " "
                aSql += " " & MyBase.COLUMN_NAME_status & " "
                aSql += " )"
                aSql += " VALUES( "
                aSql += "" & Me._id & ""
                aSql += "" & Me._cost & ""
                aSql += "" & Me._costImpoverishment & ""
                aSql += "" & Me._costRemaining & ""
                aSql += "" & Me._techCondition & ""
                aSql += "" & Me._date & ""
                aSql += "" & Me._place & ""
                aSql += "" & Me._councilInventory & ""
                aSql += "" & Me._fatype & ""
                aSql += "" & Me._status & ""
                aSql += " )"

                mySqlConnect.executeUpdate(aSql)

            Case Else

        End Select


    End Function

    Public Function delete() As Boolean
        Dim mySqlConnect As MySqlConnect
        mySqlConnect = New MySqlConnect

        Dim aSql As String
        aSql = "DELETE FROM " & MyBase.TABLE_NAME & ""
        aSql += " WHERE " & MyBase.COLUMN_NAME_id & " = " & Me._id & ""

        Return mySqlConnect.executeUpdate(aSql)

    End Function


    Public Property id() As Integer
        Get
            Return Me._id
        End Get
        Set(ByVal value As Integer)
            Me._id = value
        End Set
    End Property

    Public Property cost() As Integer
        Get
            Return Me._cost
        End Get
        Set(ByVal value As Integer)
            Me._cost = value
        End Set
    End Property

    Public Property costImpoverishment() As Integer
        Get
            Return Me._costImpoverishment
        End Get
        Set(ByVal value As Integer)
            Me._costImpoverishment = value
        End Set
    End Property

    Public Property costRemaining() As Integer
        Get
            Return Me._costRemaining
        End Get
        Set(ByVal value As Integer)
            Me._costRemaining = value
        End Set
    End Property

    Public Property techCondition() As String
        Get
            Return Me._techCondition
        End Get
        Set(ByVal value As String)
            Me._techCondition = value
        End Set
    End Property

    Public Property datetime() As Date
        Get
            Return Me._date
        End Get
        Set(ByVal value As Date)
            Me._date = value
        End Set
    End Property

    Public Property place() As String
        Get
            Return Me._place
        End Get
        Set(ByVal value As String)
            Me._place = value
        End Set
    End Property

    Public Property councilInventory() As Integer
        Get
            Return Me._councilInventory
        End Get
        Set(ByVal value As Integer)
            Me._councilInventory = value
        End Set
    End Property

    Public Property status() As Integer
        Get
            Return Me._status
        End Get
        Set(ByVal value As Integer)
            Me._status = value
        End Set
    End Property

End Class
